package com.hyl.controller;

import com.hyl.entity.SysUser;
import com.hyl.service.SysUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @Description TODO
 * @Author hyl
 * @Date 2023/5/18 10:46
 **/
@Controller
public class LoginController {

	@Resource //引用bean
	private SysUserService userService;

	@PostMapping("/login")
	public String login(String account, String password, HttpSession session){
		SysUser loginUser = userService.findByAccountAndPwd(account,password);
		//将登入用户的信息保存到==》session==》让同一个浏览器中的所有页面都可获取登入页面的信息
		session.setAttribute("userSession", loginUser);
		return "frame";//首页=》视图名
	}

	@PostMapping("/logout") //退出
	public String logout(HttpSession session){
		//将登入用户的session信息清空
		session.removeAttribute("userSession");
		return "login";//登入=》视图名
	}


}
